<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
  <title>票证识别</title>
  <link rel="stylesheet" href="../css/mui.min.css" />
  <script src="../js/mui.min.js"></script>
  <link rel="stylesheet" type="text/css" href="../css/app.css" />
  <link rel="stylesheet" href="../npl/css/vant.mini.css" />
  <link rel="stylesheet" href="../css/zengzhishui.css" />
  <script src="../js/jquery-3.6.0.min.js"></script>
  <script src="../js/flexible.js"></script>
  <script src="../js/vue.js"></script>
  <script src="../js/sm2.js"></script>
  <script src="../js/sm3.js"></script>
  <script src="../common/zzwd/mixinOcr.js"></script>
  <link rel="stylesheet" href="../common/zzwd/znwd.css">
  <!-- <script src="../js/feedback.js"></script> -->
  <script src="../js/clipboard.js"></script>
  <script src="../common/zzwd/sse.js"> </script>
  <script src="../npl/js/vant.mini.js"></script>
  <script src="../js/vconsole.min.js"></script>
  <script src="./text.js" type="text/javascript"></script>

  <style>
    .top {
      height: 7.3rem;
      width: 100%;
      box-sizing: border-box;
      font-size: 0.3rem;
      position: relative;
      border-radius: 12px;
      padding: 0;
      /* margin-bottom: 0.3rem; */
      background: none;
    }

    .frontandback {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      position: relative;
      padding: 0;
    }

    .frontandback .nameColor {
      position: absolute;
      left: 50%;
      color: #ccc;
      transform: translate(-50%);
      bottom: 1rem;
    }

    .grid_list {
      display: grid;
      grid-column-gap: 20px;
      grid-row-gap: 20px;
      /* 一行放两列、两个auto */
      grid-template-columns: auto auto;
      padding: 20px;
    }

    .grid_list {
      display: grid;
      grid-column-gap: 20px;
      grid-row-gap: 20px;
      /* 一行放两列、两个auto */
      grid-template-columns: auto auto;
      padding: 0 0.3rem;
    }

    .grid_list .grid_item {
      /* width: 152px; */
      height: 1.2rem;
    }

    .form {
      padding: 0.2rem 0.3rem;
      background-color: #f8fafe;
      line-height: 0.5rem;
      position: relative;
      border-radius: 0.2rem 0.2rem 0 0;
      overflow: auto;
    }

    .form p {
      margin-bottom: 0.1rem;
      font-size: 0.25rem;
      color: #6b7076;
      font-family: "Microsoft YaHei";
      font-weight: 600;
      display: flex;
    }

    .form .key {
      width: 55%;
      display: inline-block;
    }

    .form .value {
      width: 56%;
      display: inline-block;
      margin-left: 0.2rem;
    }

    .form .resultTitle {
      width: 50%;
      font-size: 0.2rem;
      color: #bdbfc1;
    }

    .line {
      position: absolute;
      top: 0.3rem;
      left: 0px;
      width: 100%;
      height: 5.6rem;
      z-index: 111;
    }

    .lineFlag {
      display: none;
      width: 100%;
      -webkit-animation: bounce-down 2s linear infinite;
      animation: bounce-down 2s linear infinite;
    }

    @-webkit-keyframes bounce-down {
      25% {
        -webkit-transform: translateY(0rem);
      }

      50% {
        -webkit-transform: translateY(3.3rem);
      }

      100% {
        -webkit-transform: translateY(6.8rem);
      }
    }

    @keyframes bounce-down {
      25% {
        transform: translateY(6.8rem);
      }

      50% {
        transform: translateY(3.3rem);
      }

      100% {
        transform: translateY(0rem);
      }
    }

    .title {
      background: url("../image/trainTicketsBgc.png") center;
      background-size: 100% 100%;
      width: 100%;
      height: 3.5rem;
      padding: 0rem 0.3rem;
    }

    .time {
      margin-top: 0.2rem;
      padding: 0 0.2rem;
    }

    .time p {
      font-size: 0.3rem;
      color: #000;
    }

    .time p:first-child {
      margin-right: 0.6rem;
      color: #8a9dbe;
      font-size: 0.28rem;
      font-weight: 600;
    }

    .time p:last-child {
      font-weight: 600;
      /* font-family: "宋体"; */
      font-family: "Microsoft YaHei";
      font-size: 0.28rem;
    }

    .add {
      width: 100%;
      height: 100%;
      margin: 0 auto;
      background: url("../image/shi-bg.png") center no-repeat;
      background-size: 100% 100%;
    }

    .tips-warp {
      position: fixed;
      width: 100%;
      height: 1.5rem;
      line-height: 1.2rem;
      bottom: 0.2rem;
      padding: 0.2rem 0.3rem 0;
    }

    .tips-warp img {
      width: 100%;
      height: 100%;
    }

    .tips-warp .tips {
      font-size: 0.25rem;
      line-height: 1.5;
    }

    /* 弹出框 */
    .van-dialog__header {
      padding-top: 0;
      position: relative;

    }

    .dialog_title {
      border-bottom: 1px solid #f2f2f2;
      padding: 0.3rem 0 0;
      width: 100%;
    }

    .dialog_content .dialog_title .close {
      position: absolute !important;
    }

    .dialog_content {
      min-height: 6rem;
      max-height: 7rem;
      padding: 0.3rem;
      padding-bottom: 0;
      overflow: auto;
    }

    .dialog_content .row {
      display: flex;
      margin-bottom: 10px;
    }

    .dialog_content .row_title {
      font-weight: bold;
      margin-bottom: 20px;
    }

    .dialog_content .row {
      display: flex;
    }

    .dialog_content .row .row_left {
      width: 35%;
    }

    .dialog_content .row .row_right {
      width: 65%;
    }

    .dialog_footer {
      border-top: 1px solid #f2f2f2;
      padding: 0.3rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .dialog_footer .left,
    .right {
      display: flex;
      align-items: center;
      color: #4C70F7;
    }

    .dialog_footer .left img {
      width: .4rem;
      height: .4rem;
      margin-right: 10px;
    }

    /* .dialog_footer .right img:nth-child(1) {
      width: .4rem;
      height: .4rem;
      margin-right: 20px;
    } */

    .dialog_footer .right img {
      width: 1rem;
      height: .6rem;
    }

    .dialog_footer .right img:nth-child(2) {
      margin: 0 10px;
    }

    .content1 {
      background: none !important;
      border: none;
      overflow: scroll;
      height: 100%;
      word-wrap: break-word;
      /* border-radius: 0.2rem 0.2rem 0 0; */
      padding: 0 !important;
      margin: 0 !important;
      min-height: 6rem;
      max-height: 7rem;
      padding: 0.3rem;
      /* overflow: auto */
    }

    .keyBox {
      max-height: 5.3rem;
      overflow: auto;
    }

    .tit_text {
      color: red;
      font-size: 12px;
    }

    .van-nav-bar {
      background: none !important;
      ;
    }

    .titile_ocr {
      padding: 0.36rem 0.3rem 0.15rem;
      font-weight: normal;
      font-size: 16px;
      color: #000;
    }

    .Box_wrapper {
      width: 100%;
      height: 100% !important;
    }

    .van-action-sheet {
      max-height: 90%;
    }

    .active-brightness {
      background-size: 100% 100%;
      background-repeat: no-repeat;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div class="is-loading">
      <div class="curtain" id="curtain">
        <div class="loadingBgc">
          <div class="loader"></div>
        </div>
      </div>
    </div>
    <div class="trainTickets" style="height: calc(100% - 20px)">
      <div class="header_tit">
        <van-nav-bar title="识一识" left-arrow>
          <template #left>
            <div class="back_l" @click="home">
              <img src="../image/left.png" alt="" />
            </div>
          </template>
          <template #right>
            
          </template>
        </van-nav-bar>
      </div>

      <div style="padding: 0px 0.3rem; text-align: center">
        <div class="top" @click="functionBtn">
          <img :src="addedPreviewFile" style="width: 100%; height: 100%;" alt="" v-if="addedPreviewFile !== ''" />

          <div class="frontandback" v-if="addedPreviewFile == ''">
            <p class="add"></p>
            <p class="nameColor" v-text="titleName"></p>
          </div>
          <div class="line">
            <img src="../image/scan_line.png" alt="" class="lineFlag" style="display: none; width: 100%"
              ref="lineFlag" />
          </div>
        </div>
      </div>
      <!--titile_ocr里面的文案 OCR识别 -->
      <p class="titile_ocr"></p>
      <div class="grid_list">
        <div v-for="(image, index) in images" :key="index" class="grid_item active-brightness"
          :style="{ backgroundImage: `url(${image})` }" @click="getPrint(index + 1)"></div>
      </div>
      <!-- <p class="titile_ocr">智能问答</p>-->
      <div class="tips-warp">
        <!-- <img src="../image/pzwd.png" alt="">  -->
        <p class="nameColor tips">
          <span style="color:#000">证件识别范围：</span>行驶证、驾驶证、行驶证副页、不动产证、房产证、银行卡、身份证、营业执照。
        </p>
        <p class="nameColor tips" style="margin-top: 3px;">
          <span style="color:#000">票据识别范围：</span>增值税发票、火车票、机动车发票
        </p>
      </div>
      <!-- <van-action-sheet @closed="closedVansheet" :close-on-click-overlay="false" class="Box_wrapper" v-model="showZznd"
        title="拍照问答">
        <div class="foot">
          <div id="showText">
            <div id="messageList" v-for="(item, index) in messages_show">
              <div class="user_div" v-if="item.role == 'user'">
                <div class="User_text" v-if="!item.img">
                  <div class="User_text_n">
                    {{item.content}}
                  </div>
                </div>
                <div class="User_text" style="width:150px;height:200px" v-if="item.img">
                  <div class="User_text_n" style="background:#F6F7F9;width: 82%;height:100%">
                    <img style="width: 100%;height:100%" v-if="item.img" :src="item.img" alt="">
                  </div>
                </div>
              </div>
              <div class="robot_div" v-else>
                <div class="robot_imgs">
                  <img v-if="item.img" :src="item.img" alt="">
                  <div v-if="item.content" class="robot_text">
                    {{item.content}}
                  </div>
                </div>

              </div>
            </div>
          </div>
          <footer>
            <div class="foot_wrapper">
              <div class="search">
                <img class="voice-img" src="../image/voice-play.png" @click="start" v-if="!voicing" />
                <textarea id="titleInput" :class="['search-text', voicing ? 'ml15' : '']" placeholder="请在此输入文字"
                  v-model="searchText"></textarea>
                <img class="send-img" v-if="chatting" src="../image/chat-stop.png" @click="stopChat" />
                <img class="send-img" v-if="searchText && !chatting" src="../image/send.png" @click="fileText(1)" />
                <img class="send-img" v-if="!searchText && !chatting" src="../image/no-send.png" />
              </div>
              <div class="voice" v-if="voicing">
                <div class="voice-t">
                  <img src="../image/waf.gif" />
                </div>
                <div class="voice-b">
                  <van-button class="voice-btn" type="info" @click="suspend">说完了</van-button>
                </div>
              </div>
            </div>
          </footer>
        </div>
      </van-action-sheet> -->
      <div v-if="isflageIOX==true">
        <input type="file" id="inputer" class="file-input4 file-input" @change="funcBtn" style="display: none"
          ref="inputer" />
      </div>
      <div v-else></div>
    </div>
    <!-- 打印文字识别 -->
    <van-dialog v-model="printText" :show-confirm-button="false">
      <template #title>
        <div class="dialog_title">
          <span v-text="showPT== 1 ? '打印文字识别' : '表格识别'"></span>
          <van-icon class="close" @click="printFun" name="cross" style="position: absolute;top: .4rem;right: .4rem;">
          </van-icon>
          <!-- <div v-if="showPT != 1">
            <span class="tit_text">以下内容发送邮箱后，将以表格形式展示</span>
          </div> -->
        </div>
      </template>
      <template #default>
        <div class="dialog_content">
          <div class="content1" v-if="showPT != 1">
            <table border="1">
              <tr v-for="(item,index) in table.yCellSize" :key="index">
                <td v-if="tditem.ysc == index " :rowSpan="tditem.yec-tditem.ysc+1" :colSpan="tditem.xec-tditem.xsc+1"
                  v-for="(tditem,tdindex) in table.cellInfos">
                  {{tditem.word}}
                  <!-- x:{{tditem.xsc}} -{{tditem.xec-tditem.xsc}} - y:{{tditem.ysc}} -{{tditem.yec-tditem.ysc-index}} -->
                </td>
                <!-- <td v-for="Oitem in item" :key="Oitem.id" v-text=""></td> -->
              </tr>
            </table>
          </div>
          <textarea v-else :readonly="readonly" type="text" maxlength="1000" class="content1"
            v-model='content'></textarea>
        </div>
        <div class="dialog_footer">
          <div class="left" @click="getPrint(showPT== 1 ? 1 : 2)">
            <img src="../image/refresh.png" alt="">
            <img style="margin-left: 5px;" class="tag-read" data-clipboard-target=".content1" @click="copyText('.tag-read')"
              src="../image/copy.png" alt="">
          </div>
          <div class="right">
            <img @click="sendEmail(showPT,0)" src="../image/shuoyishuo_youx.png" alt="">
            <img @click="sendEmail(showPT,3)" src="../image/tb.png" alt="">
            <img @click="checkJion(showPT)" src="../image/join1.png" alt="">
            
          </div>
        </div>
      </template>
    </van-dialog>
    <!-- 证件识别 -->
    <van-dialog v-model="certificate" :show-confirm-button="false">
      <template #title>
        <div class="dialog_title">
          <span v-text="pjANDzj == 3 ? '证件识别': '票据识别' ">证件识别</span>
          <van-icon class="close" @click="certiFicate" name="cross" style="position: absolute;top: .4rem;right: .4rem;">
          </van-icon>
        </div>
      </template>
      <template #default>
        <!-- <div class="dialog_content"> -->
        <div class="form" id="copyValue">
          <p>
            <span class="resultTitle">名称</span>
            <span class="resultTitle">识别结果</span>
          </p>
          <div class="keyBox">
            <p v-for="(item, key) in form.result" :key="key">
              <span class="key">{{key}}:</span>
              <span class="value">
                {{item}}
                <img v-if="key == '身份证号码'" src="../image/ocrcopy.png" style="width: 0.3rem; margin-left: 10px"
                  @click="copyIdNumber" class="idNumber-read" />
              </span>
            </p>
          </div>
        </div>
        <!-- </div> -->
        <div class="dialog_footer">
          <div class="left" @click="getPrint(pjANDzj == 3 ? 3 : 4)">
            <img src="../image/refresh.png" alt="">
            <img style="margin-left: 5px;" @click="copy" class="tag-reads" src="../image/copy.png" alt="">
          </div>
          <div class="right">
            
          
            <img @click="sendEmail(3,0)" src="../image/shuoyishuo_youx.png" alt="">
            <img @click="sendEmail(3,3)" src="../image/tb.png" alt="">
            <img @click="checkJionText(3)" src="../image/join1.png" alt="">
          </div>
        </div>
      </template>
    </van-dialog>
  </div>
  <script>
    new Vue({
      el: "#app",
      mixins: [ocrData],
      data() {
        return {
          images: [
            '../image/dy.png',
            '../image/biaog.png',
            '../image/zj.png',
            '../image/pj.png'
          ],
          readonly: true,
          chatting: false,
          titleName: "点击此处上传图片",
          isflageIOX: true,
          type: "身份证正面",
          content: '',
          form: {
            result: {},
          },
          tableContent: '',
          tableResvale: '',
          showPT: 2,
          addedPreviewFile: "",
          timestamp: "",
          accesstoken: "",
          printText: false, //打印文字识别
          certificate: false, //证件识别
          pjANDzj: 3,
          table: [],
          // tableObj: {}
        };
      },
      created() {
        const _this = this;
        _this.compatibleInput();
        let jsApiList = [];
        $.getScript(
          "../js/jweixin-sgccigw-1.0.0.js" /*"js/jweixin-1.0.0.js"*/ ,
          function () {
            "use strict";
            wx.ready(function () {
              wx.onHistoryBack(() => {
                _this.home();
                return false;
              });
            });
            jsApiList = [
              'startRecord',
              'stopRecord',
              'onVoiceRecordEnd',
              'translateVoice',
              'onHistoryBack',
              "onHistoryBack",
              "ext_FileManager_Information",
              "chooseImage",
              "getLocalResPath",
              "getLocalImgData",
            ];
            wx.config({
              beta: true,
              debug: false,
              appId: corpid,
              timestamp: "1626832073",
              nonceStr: nonceStr,
              signature: signature,
              jsApiList: jsApiList,
            });
          }
        );
      },
      methods: {
        checkJion(num) {
          $("#curtain").css("display", "block");
          let url
          data = {
            sceneNo: num == 1 ? 1 : 6,
            text: num == 1 ? this.content : this.tableResvale,
            title: ''
          }
          num == 1 ? url = "/tjAiAssistant/shareFile/shareToBase64" : url =
            "/tjAiAssistant/shareFile/shareExcelToBase64"
          var data = greneralRequest(url, JSON.stringify(data))
        },
        checkJionText(num) {
          $("#curtain").css("display", "block");
          var text1 = JSON.stringify(this.form.result);
          text1 = text1.replace(/"/g, "");
          text1 = text1.replace(/{/g, "");
          text1 = text1.replace(/}/g, "");
          text1 = text1.replace(/,/g, "\n");
          data = {
            sceneNo: this.pjANDzj == 3 ? "52" : '53',
            text: text1,
            title: ''
          }
          var data = greneralRequest("/tjAiAssistant/shareFile/shareToBase64", JSON.stringify(data))
        },
        printFun() {
          this.printText = false
          this.content = ''
          this.addedPreviewFile = ''
          this.tableContent = ''
          this.tableResvale = ''
        },
        certiFicate() {
          this.certificate = false
          this.form.result = {}
          this.addedPreviewFile = ''
        },
        compatibleInput() {
          var ua = navigator.userAgent.toLowerCase();
          var isIos = ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1;
          if (isIos) {
            this.isflageIOX = true;
          } else {
            this.isflageIOX = false;
          }
        },
        groupBy(array, id) {
          let groups = {};
          array.forEach(function (o) {
            let group = JSON.stringify(o[id]);
            groups[group] = groups[group] || [];
            groups[group].push(o);
          });
          return Object.values(groups);
        },
        groupBy1(array, id) {
          let groups = {};
          array.forEach(function (o) {
            let group = JSON.stringify(o[id]);
            groups[group] = groups[group] || [];
            groups[group].push(o);
          });
          return JSON.stringify(groups)
        },
        // 选择文件
        functionBtn(num) {
          if (this.isflageIOX == true) {
            wx.chooseImage({
              count: 1,
              sizeType: ["compressed"],
              sourceType: ["album", "camera"],
              quality: 0.3,
              success: (res) => {
                var localIds = res.localIds[0];
                $(".curtain").css("display", "block");
                let slocalResPath = "";
                wx.invoke(
                  "getLocalResPath", {
                    localId: localIds,
                  },
                  (res) => {
                    slocalResPath = res.localResPath;
                    wx.invoke(
                      "ext_FileManager_Information", {
                        data: {
                          path: slocalResPath,
                        },
                      },
                      (res) => {
                        let str = JSON.parse(res.data);
                        // console.log(str, 8888)
                        // if (checkFileNameForSensitiveWords(str.fileName)) {
                        //   mui.toast('检测到敏感内容，请确认后再试。', {
                        //     duration: 'long',
                        //     type: 'div'
                        //   })
                        //   return false
                        // }
                        str = str.fileSize.split(".");
                        if (str[1].indexOf("kB") !== -1) {
                          this.getImgBase(localIds);
                        } else {
                          if (str[0] >= 3) {
                            $(".curtain").css("display", "none");
                            mui.toast("图片过大,请重新选择!", {
                              duration: "long",
                              type: "div",
                            });
                          } else {
                            this.getImgBase(localIds);
                          }
                        }
                      }
                    );
                  }
                );
              },
            });
          } else {
            wx.chooseImage({
              count: 1,
              sizeType: ["compressed"],
              sourceType: ["album", "camera"],
              quality: 0.1,
              success: (res) => {
                var localIds = res.localIds[0];
                $(".curtain").css("display", "block");
                let slocalResPath = "";
                wx.invoke(
                  "getLocalResPath", {
                    localId: localIds,
                  },
                  (res) => {
                    slocalResPath = res.localResPath;
                    wx.invoke(
                      "ext_FileManager_Information", {
                        data: {
                          path: slocalResPath,
                        },
                      },
                      (res) => {
                        let str = JSON.parse(res.data);
                        // if (checkFileNameForSensitiveWords(str.fileName)) {
                        //   mui.toast('检测到敏感内容，请确认后再试。', {
                        //     duration: 'long',
                        //     type: 'div'
                        //   })
                        //   return false
                        // }
                        // console.log(str, 88886)
                        str = str.fileSize.split(".");
                        if (str[1].indexOf("KB") !== -1) {
                          this.getImgBase(localIds);
                        } else {
                          if (str[0] >= 3) {
                            $(".curtain").css("display", "none");
                            mui.toast("图片过大,请重新选择!", {
                              duration: "long",
                              type: "div",
                            });
                          } else {
                            this.getImgBase(localIds);
                          }
                        }
                      }
                    );
                  }
                );
              },
            });
          }
        },
        getImgBase(localIds) {
          wx.getLocalImgData({
            localId: localIds,
            success: (res) => {
              let localData = res.localData;
              if (localData.indexOf("data:image") != 0) {
                localData = "data:image/jpeg;base64," + localData;
              }
              localData = localData
                .replace(/\r|\n/g, "")
                .replace("data:image/jpg", "data:image/jpeg");

              this.addedPreviewFile = localData;
              $(".curtain").css("display", "none");
              // this.getPrintReq();
            },
          });
        },
        showSize(base64url) {
          var str = base64url.replace("data:image/png;base64,", "");
          var equalIndex = str.indexOf("=");
          if (str.indexOf("=") > 0) {
            str = str.substring(0, equalIndex);
          }
          var strLength = str.length;
          var fileLength = parseInt(strLength - (strLength / 8) * 2);
          var size = "";
          size = (fileLength / 1024).toFixed(2);
          var sizeStr = size + "";
          var index = sizeStr.indexOf(".");
          var dou = sizeStr.substr(index + 1, 2);
          if (dou == "00") {
            return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
          }
          return size;
        },
        funcBtn() {
          $(".curtain").css("display", "block");
          let inputDOM = this.$refs.inputer;
          let file = inputDOM.files[0];
          if (!file) return;
          let re = new FileReader();
          re.readAsDataURL(file);
          let that = this;
          re.onload = (re) => {
            that.addedPreviewFile = re.target.result;
            console.log(re.target.result, 7777)
            var size = this.showSize(that.addedPreviewFile);
            if (size > 10000) {
              $(".curtain").css("display", "none");
              mui.toast("图片大小不能超过10M", {
                duration: "long",
                type: "div",
              });
              that.addedPreviewFile = "";
            } else {
              $(".curtain").css("display", "none");
              // this.getPrintReq();
            }
          };
        },
        // 打印文字识别接口
        getPrint(num) {
          if (!this.addedPreviewFile) {
            mui.toast("请先上传图片", {
              duration: "long",
              type: "div",
            });
            return
          }
          this.printText = false
          this.certificate = false
          this.content = ''
          this.form.result = {}
          $(".curtain").css("display", "block");
          let userId = sessionStorage.getItem("userId");
          let Authentication = sessionStorage.getItem("Authentication");
          let timestampOcr = Date.now();
          let iscp_port
          if (sessionStorage.getItem("iscp_port")) {
            iscp_port = sessionStorage.getItem("iscp_port");
          } else {
            iscp_port = ""
          }
          // const addedPreviewFile = this.addedPreviewFile.split(',')[1]
          var ocrData = {
            img: this.addedPreviewFile,
            row: "true",
            rotate: "true",
            timestamp: timestampOcr,
          };
          var URL
          if (num == 1) {
            // 打印文字识别
            URL = localUrlLink + iscp_port +
              "/tjAiAssistant/transmit/prod-api/api-ocr/v1/ocrservice/default/default/biz-ty"
          } else if (num == 2) {
            //表格识别
            ocrData.table = "true"
            URL = localUrlLink + iscp_port +
              "/tjAiAssistant/transmit/prod-api/api-ocr/v1/ocrservice/default/default/table-true"
          } else {
            // 票据识别
            URL = localUrlLink + iscp_port +
              "/tjAiAssistant/transmit/prod-api/api-ocr/v1/ocrstructuredservice/doctype/default/biz-tpzdfl"
          }
          this.$refs.lineFlag.style.display = "block";

          setTimeout(() => {
            ocrData = JSON.stringify(ocrData);
            let ocrSign = this.createSgin(ocrData);
            const timestamp = new Date().getTime() + ""
            let sign = sm3(userId + "&" + timestamp)

            $(".curtain").css("display", "none");

            $.ajax({
              url: URL,
              type: "post",
              // async: true, //是否同步，false表示同步请求
              dataType: "json",
              data: ocrData,
              headers: {
                "Content-Type": "application/json;charset=UTF-8",
                sign: sign,
                ocrSign: ocrSign,
                timestamp: timestamp,
                userId: userId,
                Authentication: Authentication
              },

              success: (res, txt, xhr) => {
                console.log(444)
                //
                if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                  let Authentication = xhr.getResponseHeader("Authentication")
                  console.log(res, 222)
                  if (res.code == 200) {
                    this.$refs.lineFlag.style.display = "none";
                    sessionStorage.setItem("Authentication", Authentication);
                    if (num == 1) {
                      this.printsFun(res)
                      addOperator(2, 1, "识别", 1, 1, "识别成功");
                    } else if (num == 2) {
                      this.tableFun(res)
                      addOperator(2, 6, "识别", 1, 1, "识别成功");
                    } else {
                      this.tpzdfFun(num, res)
                      addOperator(2, 18, "识别", 1, 1, "识别成功");
                    }
                    // 更改ocr使用次数
                    // }
                  } else {
                    this.addedPreviewFile = ''
                    this.$refs.lineFlag.style.display = "none";
                    mui.toast("不支持该图片", {
                      duration: "long",
                      type: "div",
                    }); 
                    if (num == 1) {
                      addOperator(2, 1, "识别", 1, 0, "识别失败");
                    } else if (num == 2) {
                      addOperator(2, 6, "识别", 1, 0, "识别失败");
                    } else {
                      addOperator(2, 18, "识别", 1, 0, "识别失败");
                    }
                  }
                } else {
                  this.$refs.lineFlag.style.display = "none";
                  mui.toast('完整性校验失败', {
                    duration: 'long',
                    type: 'div'
                  })
                  if (num == 1) {
                    addOperator(2, 1, "识别", 1, 0, "识别失败");
                  } else if (num == 2) {
                    addOperator(2, 6, "识别", 1, 0, "识别失败");
                  } else {
                    addOperator(2, 18, "识别", 1, 0, "识别失败");
                  }
                }
                // 
              },
              error: (e) => {
                this.$refs.lineFlag.style.display = "none";
                mui.toast("请求异常请稍后再试", {
                  duration: 'long',
                  type: 'div'
                })
                if (num == 1) {
                  addOperator(2, 1, "识别", 1, 0, "请求失败");
                } else if (num == 2) {
                  addOperator(2, 6, "识别", 1, 0, "请求失败");
                } else {
                  addOperator(2, 18, "识别", 1, 0, "请求失败");
                }
              },
            });
          }, 400)
        },
        // 打印文字识别的处理
        printsFun(res) {
          let con = JSON.parse(res.resultValue)
          if (!con.data.prism_rowsInfo || con.data.prism_rowsInfo.length == 0) { //总部
            this.addedPreviewFile = ''
            mui.toast("未识别到文字，请重新上传！", {
              duration: 'long',
              type: 'div'
            })
            return
          } else {
            con.data.prism_rowsInfo.forEach((i) => {
              return this.content += i.word + '\n'
            })
            this.showPT = 1
            this.printText = true
          }
        },
        //表格的处理逻辑
        tableFun(res) {
          this.tableResvale = res.resultValue
          let con = JSON.parse(res.resultValue)
          if (!con.prism_tablesInfo) {
            this.addedPreviewFile = ''
            mui.toast("未识出表格，请重新上传！", {
              duration: 'long',
              type: 'div'
            })

            return
          } else {
            this.tableContent = con.content
            let content = con.prism_tablesInfo[0].cellInfos
            // let arr = content;
            // let arr1 = "";
            // arr1 = this.groupBy(
            //   content,
            //   "ysc"
            // );
            // this.content = con.content
            this.table = con.prism_tablesInfo[0];
            // this.tableObj = arr;
            // this.tableObj = this.groupBy1(
            //   content,
            //   "ysc"
            // );
            this.showPT = 2
            this.printText = true
          }
        },
        //票据的处理逻辑
        tpzdfFun(num, res) {
          this.pjANDzj = num
          if (
            res.code == 200 &&
            JSON.parse(res.resultValue).data.data
          ) {
            this.$refs.lineFlag.style.display = "none";
            // 空值判断
            this.form.result = JSON.parse(res.resultValue).data.data;
            var privateKey = homeKey;
            const encryptionField = []; // 加密字段
            var halfNum = parseInt(privateKey.length / 2);
            var privateKeyStr = privateKey.slice(0, halfNum);
            var privateKeyByte = this.byteToString(
              JSON.parse(
                JSON.stringify(
                  this.stringToByte(privateKey.slice(halfNum))
                )
              )
            ).replace(privateKeyStr, "");
            // 解密
            for (const key in this.form.result) {
              const element = this.form.result[key];
              if (
                encryptionField.indexOf(key) !== -1 &&
                element !== "" &&
                element !== null &&
                element !== undefined
              ) {
                this.form.result[key] = sm2.doDecrypt(
                  name.substring(2),
                  privateKeyStr + privateKeyByte,
                  (cipherMode = 0)
                );
              }
            }
            this.certificate = true
          } else {
            this.$refs.lineFlag.style.display = "none";
            this.addedPreviewFile = "";
            mui.toast("不支持该图片", {
              duration: "long",
              type: "div",
            });
          }
        },
        stringToByte(str) {
          str = homeKey;
          var bytes = new Array();
          var len, c;
          len = str.length;
          for (var i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if (c >= 0x010000 && c <= 0x10ffff) {
              bytes.push(((c >> 18) & 0x07) | 0xf0);
              bytes.push(((c >> 12) & 0x3f) | 0x80);
              bytes.push(((c >> 6) & 0x3f) | 0x80);
              bytes.push((c & 0x3f) | 0x80);
            } else if (c >= 0x000800 && c <= 0x00ffff) {
              bytes.push(((c >> 12) & 0x0f) | 0xe0);
              bytes.push(((c >> 6) & 0x3f) | 0x80);
              bytes.push((c & 0x3f) | 0x80);
            } else if (c >= 0x000080 && c <= 0x0007ff) {
              bytes.push(((c >> 6) & 0x1f) | 0xc0);
              bytes.push((c & 0x3f) | 0x80);
            } else {
              bytes.push(c & 0xff);
            }
          }
          return bytes;
        },
        byteToString(arr) {
          if (typeof arr === "string") {
            return arr;
          }
          var str = "";
          var _arr = arr;
          for (var i = 0; i < _arr.length; i++) {
            var one = _arr[i].toString(2);
            var v = one.match(/^1+?(?=0)/);
            if (v && one.length === 8) {
              var bytesLength = v[0].length;
              var store = _arr[i].toString(2).slice(7 - bytesLength);
              for (var st = 1; st < bytesLength; st++) {
                store += _arr[st + i].toString(2).slice(2);
              }
              str += String.fromCharCode(parseInt(store, 2));
              i += bytesLength - 1;
            } else {
              str += String.fromCharCode(_arr[i]);
            }
          }
          return str;
        },
        sendEmail(num,id) {
          let text = id == 3 ? "是否同步至内网网站？" : "是否发送邮箱？"
          var btnArray = ["取消", "确定"];
          var i = 0;
          mui.confirm(text, "消息提醒", btnArray, (e) => {
            if (i > 0) return;
            i++;
            if (e.index == 1) {
              this.mailbox(num,id);
            }
          });
        },
        // 发送邮件
        mailbox(num,id) {
          $(".curtain").css("display", "block");
          if (num == 1) {
            var text1 = this.content
            var obj = {
              sceneName: "打印文字识别",
              sceneNo: "1",
              fileName: "打印文字识别.txt",
            }
          } else if (num == 2) {
            var text1 = this.tableResvale
            var obj = {
              sceneName: "表格识别",
              sceneNo: "6",
              fileName: "表格识别.txt",
            }
          } else {
            var text1 = JSON.stringify(this.form.result);
            text1 = text1.replace(/"/g, "");
            text1 = text1.replace(/{/g, "");
            text1 = text1.replace(/}/g, "");
            text1 = text1.replace(/,/g, "\n");
            var obj = {
              sceneName: "票识别",
              sceneNo: this.pjANDzj == 3 ? "52" : '53',
              fileName: "票识别.txt",
            }
          }
          var data = {
            fileExt: ".txt",
            fileContent: text1,
            orgId: "1",
            userId: userId,
            userName: userName,
            toMail: "",
            saveType:id,
            timestamp: new Date().getTime() + "",
          };
          data = {
            ...data,
            ...obj
          }
          let mailboxReturn = mailbox(
            data.sceneNo,
            data.fileName,
            data.fileExt,
            data.fileContent,
            data.orgId,
            data.userId,
            data.userName,
            data.toMail,
            data.saveType,
            data.timestamp
          );
          if (mailboxReturn == 200) {
            this.addedPreviewFile = ''
            this.printText = false
            this.certificate = false
            this.content = ''
            this.form.result = {}
            if (num == 1) {
              addOperator(2, 1, "发送邮箱", 1, 1, "发送邮箱成功");
            } else if (num == 2) {
              addOperator(2, 6, "发送邮箱", 1, 1, "发送邮箱成功");
            } else {
              addOperator(2, 18, "发送邮箱", 1, 1, "发送邮箱成功");
            }
          } else {
            if (num == 1) {
              addOperator(2, 1, "发送邮箱", 1, 0, "发送邮箱失败");
            } else if (num == 2) {
              addOperator(2, 6, "发送邮箱", 1, 0, "发送邮箱失败");
            } else {
              addOperator(2, 18, "发送邮箱", 1, 0, "发送邮箱失败");
            }
          }
        },
        //复制按钮
        copyText(name) {
          var text1 = ""
          if (this.showPT == 1) {
            if (!this.content || this.content.split(" ").join("").length == 0) {
              mui.toast('内容不能为空', {
                duration: 'long',
                type: 'div'
              })
              return false
            }
            text1 = this.content;
          } else {
            text1 = this.tableContent
          }

          var clipboard = new Clipboard(name, {
            // 通过target指定要复印的节点
            text: function () {
              return text1;
            },
          });
          clipboard.on("success", (e) => {
            if (this.showPT == 1) {
              addOperator(2, 1, "复制文本", 1, 1, "复制成功");
            } else {
              addOperator(2, 6, "复制文本", 1, 1, "复制成功");
            }

            mui.toast("复制成功", {
              duration: "long",
              type: "div"
            });
          });

          clipboard.on("error", (e) => {
            if (this.showPT == 1) {
              addOperator(2, 1, "复制文本", 1, 0, "复制失败");
            } else {
              addOperator(2, 6, "复制文本", 1, 0, "复制失败");
            }
          });
        },
        // 复制所有文本
        copy() {
          var that = this;
          var text1 = JSON.stringify(that.form.result);
          text1 = text1.replace(/"/g, "");
          text1 = text1.replace(/{/g, "");
          text1 = text1.replace(/}/g, "");
          text1 = text1.replace(/,/g, "\n");
          var clipboard = new Clipboard(".tag-reads", {
            text: function () {
              return text1;
            },
          });
          clipboard.on("success", (e) => {
            addOperator(2, 18, "复制文本", 1, 1, "复制成功");
            mui.toast("复制成功", {
              duration: "long",
              type: "div",
            });
          });
          clipboard.on("error", (e) => {
            addOperator(2, 18, "复制文本", 1, 0, "复制失败");
          });
        },
        // 复制身份证
        copyIdNumber() {
          var that = this;
          var text = that.form.result["身份证号码"];
          var clipboard = new Clipboard(".idNumber-read", {
            text: function () {
              return text;
            },
          });
          clipboard.on("success", (e) => {
            addOperator(2, 18, "复制文本", 1, 1, "复制成功");
            mui.toast("复制成功", {
              duration: "long",
              type: "div",
            });
          });
          clipboard.on("error", (e) => {
            addOperator(2, 18, "复制文本", 1, 0, "复制失败");
          });
        },
        home() {
          // $(location).attr("href", "Home.html");
          // if (this.disno) {
          //     this.disno = !this.disno
          // } else {
          $(location).attr("href", "Home.html");
          // }
        },
        createSgin(data) {
          let hashData = sm3(data);
          let hashData_last = sm3(hashData);
          hashData_last = hashData_last.substr(0, 5);
          hashData += hashData_last;
          let sign = hashData;
          return sign;
        },
      },
    });
  </script>
</body>

</html>